import React from 'react'
import { Router, Route, Switch, Redirect } from 'react-router-dom'
import Login from './pages/Login'
import Layout from './pages/Layout'
import NotFound from './pages/NotFound'
import history from './utils/history'
import PrivateRoute from './components/PrivateRoute'
// BrowserRouter = Router + history
export default function App() {
  return (
    <Router history={history}>
      <Switch>
        {/* 重定向到 /home */}
        <Redirect exact from='/' to='/home' />
        <Route path='/login' component={Login} />
        {/* /home 对应的就是 Layout */}
        {/* <Route path='/home' component={Layout} /> */}
        {/* <Route path='/home'>
          <Layout />
        </Route> */}
        {/* <Route
          path='/home'
          render={() => {
            if (isHasToken()) {
              return <Layout />
            } else {
              return <Redirect to='/login' />
            }
          }}
        /> */}
        <PrivateRoute path='/home' component={Layout} />
        {/* 包裹的子元素会被当做 children 属性进行传递 */}
        {/* <PrivateRoute path='/home'>
          <Layout />
        </PrivateRoute> */}
        <Route component={NotFound} />
      </Switch>
    </Router>
  )
}
